**********************************************************************************************************************
***********		Table 5 columns I-II - Hedonic Price Function Estimates: 
***********		Robustness Checks (Non-Parameteric Estimates)
**********************************************************************************************************************


use ".\data\clean\I10W_laneuse_dataset_15nov14_wcensus", clear

merge m:1 date hour using ".\data\clean\HV_ML_reliab.dta", keep(1 3) nogen 
gen reliabilityML=dist/p20_speedML-dist/p50_speedML
gen reliabilityHV=dist/p20_speedHV-dist/p50_speedHV
gen reliability_diff=reliabilityML-reliabilityHV

*WTP calculation
gen TT_dif_hr=dist/MLspeed-dist/ELspeed
gen WTP2=charged_toll/TT_dif_hr
drop if ELspeed==.
drop if TT_dif_hr==.
drop if holiday==1
la var TT_dif_hr "Time in Hours"
drop if dow==0|dow==6
keep if acct_type=="PRIVATE"&occupancy~="HOV-3"
keep if hour>4 & hour<9
replace reliability_diff=0 if reliability_diff<0.01
keep if reliability_diff~=.
la var reliability_diff "Reliability"
drop if TT_dif_hr<=0

g week=week(date)




/*
qui sum week
local min=`r(min)'
local max=`r(max)'
forval w=`min'/`max'{
	qui reg  charged_toll TT_dif_hr reliability_diff if week==`w', cluster(rt_id)
	est sto a`w'
	di ".",_cont
}
esttab  a*   using ".\results\revision1\weekly.csv", replace  ///
	cells(b(star fmt(%9.3f)) se(par)) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(r2 N ,fmt(%9.2f %9.0g) ///
		labels(R-squared N )) ///
	title("Weekly regressions")  ///
	 nonumbers nodepvars label
*/
*g week=week(date)

local m=7
capture est sto clear
capture log close
log using ".\results\revision1\nparam_m`m'.txt", replace text
keep if month==`m'
npregress kernel charged_toll TT_dif_hr reliability_diff, reps(100) seed(1234)
est sto a1

esttab  a1   using ".\results\revision1\nparam_m`m'.csv", replace  ///
	cells(b(star fmt(%9.3f)) se(par)) star(* 0.10 ** 0.05 *** 0.01) ///
	stats(r2 N ,fmt(%9.2f %9.0g) ///
		labels(R-squared N )) ///
	title("Non-parametric regression for AM Peak Month `w'")  ///
	 nonumbers nodepvars label

twoway kdensity _Mean_charged_toll, title("Value of Urgency") xtitle("$ per trip") ytitle("density")
graph export .\results\revision1\VOU_nparam_m`m'.png, replace

twoway kdensity _d_Mean_charged_toll_dTT_dif_hr, title("Value of Time") xtitle("$ per hour") ytitle("density")

graph export .\results\revision1\VOT_nparam_m`m'.png, replace

twoway kdensity _d_Mean_charged_toll_dreliabilit, title("Value of Reliability") xtitle("$ per hour") ytitle("density")

graph export .\results\revision1\VOR_nparam_m`m'.png, replace
save .\results\revision1\nparam_m`m',replace
log close
